package com.baimawangzi.recovery.service.impl;

import com.baimawangzi.recovery.bean.Integral;
import com.baimawangzi.recovery.bean.PageBean;
import com.baimawangzi.recovery.dao.IntegralDao;
import com.baimawangzi.recovery.dao.impl.IntegeralDaoImpl;
import com.baimawangzi.recovery.service.IntegralService;

import java.util.List;

public class IntegralServiceImpl implements IntegralService {
    private IntegralDao integralDao = new IntegeralDaoImpl();
    @Override
    public List<Integral> findByLimit(int m, int n) {
        return integralDao.findByLimit(m,n);
    }

    @Override
    public Integral findById(int id) {
        return integralDao.findById(id);
    }

    @Override
    public int update(Integral integral) {
        return integralDao.update(integral);
    }

    @Override
    public PageBean<Integral> getPageBean(int currentPage, int pageSize) {
        PageBean<Integral> pageBean = new PageBean<>();
        pageBean.setCurrentPage(currentPage);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalSize(integralDao.getCount());
        if (pageBean.getTotalSize()%pageSize==0){
            pageBean.setTotalPage(pageBean.getTotalSize()/pageSize);
        }
        else {
            pageBean.setTotalPage(pageBean.getTotalSize()/pageSize+1);
        }
        int m =(currentPage-1)*pageSize;
        pageBean.setData(integralDao.findByLimit(m,pageSize));
        return pageBean;
    }
}
